<template>
    <div style="width: 420px">
        <h6>请输入要搜索的商品Id的商品名,enter键确认</h6>
        <el-input v-model="searchName" clearable placeholder="请输入搜索的商品名"  prefix-icon="el-icon-search" @keydown.native.enter="searchId">
        </el-input>
        <div>
            <p v-for="(item, index) in goods" :key="index"><strong>商品名称：</strong>&nbsp;{{item.name}} <strong>商品id：</strong> {{item.id}}</p>
        </div>
    </div>
</template>

<script>
    import {sendwithpost} from "../../../../network/profile";

    export default {
        name: "GoodsNameToId",
        data() {
            return {
                searchName: '',
                showId: '',
                goods: []
            }
        },
        methods: {
            searchId() {
                sendwithpost({
                    url: '/searchName',
                    data: {
                        searchName: this.searchName
                    }
                }).then(res=> {
                   this.$message({
                       showClose: true,
                       message: res.data.message,
                       type: res.data.type
                   })
                    if (res.data.res_code == 2) {
                        this.goods = res.data.goods
                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>